<template>
    <div class="exposure-content">
        <div class="move-box">
            <RiskLeftModule
                v-model="leftKey"
                @on-submit="submitInput"
                @on-handleNode="clickNode"
                :placeholders="leftplaceholder"
                :treeData="treeData"
                :leftHeight="leftHgt"
                :currentKey="2"
                :defaultExpandedKeys="defaultExpandedKeys"
            >
                <template slot="ltitle">敞口信息</template>
            </RiskLeftModule>
            <template v-if="cutInfo === '本地' || cutInfo === '外部'">
                <RiskRightModule v-model="rightKey" :rightPlace="rightplaceHolder" :rightHeight="leftHgt" @on-keyup="searchExposure">
                    <p slot="rtitle">敞口明细信息</p>
                    <span slot="button" class="dict-r-slot">
                        <el-button type="primary" size="mini" @click="searchExposure">查询</el-button>
                    </span>
                    <span slot="button" class="dict-r-slot">
                        <el-button type="primary" size="mini" v-show="cutInfo === '本地'" v-authCode.show="B_0113" @click="openAddExposoreDialog"
                            >新增</el-button
                        >
                    </span>
                    <span slot="button" class="dict-r-slot">
                        <el-button type="primary" size="mini" v-authCode.show="B_0144" @click="handleExport">导出</el-button>
                    </span>

                    <span slot="button" class="dict-r-slot">
                        <el-button type="danger" size="mini" v-show="cutInfo === '本地'" v-authCode.show="B_0114" @click="handleExposureRemove(-1)"
                            >删除</el-button
                        >
                    </span>
                    <slot>
                        <el-table
                            :data="exposureData"
                            border
                            size="mini"
                            style="width: 100%"
                            max-height="680px"
                            height="79vh"
                            @selection-change="handleSelectionChange"
                        >
                            <el-table-column type="selection" width="55" size="mini" align="center"> </el-table-column>
                            <el-table-column prop="exposureId" label="产品敞口编号"> </el-table-column>
                            <el-table-column prop="exposureName" label="敞口名称" show-overflow-tooltip> </el-table-column>
                            <el-table-column prop="modifyUser" label="修改人" show-overflow-tooltip> </el-table-column>
                            <el-table-column prop="modifyDate" label="修改日期" align="center" sortable>
                                <template slot-scope="scope">
                                    <span>{{ dateFormat(scope.row.modifyDate) }} {{ timeFormat(scope.row.modifyTime) }}</span>
                                </template>
                            </el-table-column>
                            <!-- <el-table-column prop="modifyTime" label="修改时间" show-overflow-tooltip :formatter="formatterTime" align="center">
                            </el-table-column> -->

                            <el-table-column label="操作" width="120">
                                <template slot-scope="scope">
                                    <RiskIconButton
                                        type="primary"
                                        icon="el-icon-edit"
                                        topTitle="编辑"
                                        v-authCode="B_0188"
                                        @on-click="openEditExposureDialog(scope.row)"
                                    ></RiskIconButton>
                                    <RiskIconButton
                                        type="danger"
                                        icon="el-icon-delete"
                                        topTitle="删除"
                                        v-authCode="B_0191"
                                        @on-click="handleExposureRemove(scope.row.exposureId)"
                                    ></RiskIconButton>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="block">
                            <risk-pagination :paging="exposurePage" @page-change="pageRet"></risk-pagination>
                        </div>
                    </slot>
                </RiskRightModule>
                <!-- 新增敞口 -->
                <yh-dialog drag :title="exposureDialogVO.title" :visible.sync="exposureDialogVO.visible" width="400px" v-loading="loading">
                    <el-form label-width="100px" size="mini" ref="exposureForm">
                        <el-form-item label="敞口编号" prop="exposureId">
                            <el-input placeholder="自动生成" style="width: 220px" v-model="exposureForm.exposureId" disabled></el-input>
                        </el-form-item>
                        <el-form-item label="敞口名称" prop="exposureName">
                            <el-input style="width: 220px" v-model="exposureForm.exposureName"></el-input>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button size="mini" @click="closeExposureDialog"> 取 消 </el-button>
                        <el-button size="mini" type="primary" @click="submitExposureForm"> 确 定 </el-button>
                    </div>
                </yh-dialog>
                <!-- 删除敞口 -->
                <yh-dialog drag title="确认删除敞口信息？" :visible.sync="removeDialog" width="500px" v-loading="loading">
                    <div class="remove-text">
                        <span v-for="(item, index) in exposureIdList" :key="index"> {{ item }} , </span>
                    </div>
                    <div slot="footer" class="dialog-footer">
                        <el-button size="mini" @click="removeDialog = false"> 取 消 </el-button>
                        <el-button size="mini" type="primary" @click="removeExposure">确 定 </el-button>
                    </div>
                </yh-dialog>
            </template>

            <template v-else>
                <RiskRightModule v-model="rightKey2" :rightPlace="rightplaceHolder2" :rightHeight="leftHgt" @on-keyup="searchExposureFund">
                    <p slot="rtitle">敞口明细信息</p>
                    <span slot="button" class="dict-r-slot">
                        <el-button type="primary" size="mini" @click="searchExposureFund">查询</el-button>
                    </span>
                    <span slot="button" class="dict-r-slot">
                        <el-button type="primary" size="mini" @click="openAddFundDialog">新增</el-button>
                    </span>
                    <span slot="button" class="dict-r-slot">
                        <el-button type="primary" size="mini" @click="handleExportFund">导出明细</el-button>
                    </span>
                    <span slot="button" class="dict-r-slot">
                        <el-button type="primary" size="mini" @click="importFundDialog = true">导入明细</el-button>
                    </span>
                    <span slot="button" class="dict-r-slot">
                        <el-button type="danger" size="mini" @click="handleRemoveFund(-1)">删除</el-button>
                    </span>
                    <slot>
                        <el-table
                            :data="exposureDetialData"
                            border
                            size="mini"
                            style="width: 100%"
                            max-height="680px"
                            height="79vh"
                            @selection-change="handleSelectionFundChange"
                        >
                            <el-table-column type="selection" width="55" size="mini" align="center"> </el-table-column>
                            <el-table-column prop="fundCode" label="产品代码"> </el-table-column>
                            <el-table-column prop="fundNameSt" label="产品名称" show-overflow-tooltip> </el-table-column>
                            <el-table-column prop="exposureValue" label="敞口值" show-overflow-tooltip :formatter="formatterNumber" align="right">
                            </el-table-column>
                            <el-table-column prop="modifyUser" label="修改人" show-overflow-tooltip> </el-table-column>
                            <el-table-column prop="modifyDate" label="修改日期" align="center" sortable>
                                <template slot-scope="scope">
                                    <span>{{ dateFormat(scope.row.modifyDate) }} {{ timeFormat(scope.row.modifyTime) }}</span>
                                </template>
                            </el-table-column>
                            <!-- <el-table-column prop="modifyTime" label="修改时间" show-overflow-tooltip :formatter="formatterTime" align="center"> -->
                            <!-- </el-table-column> -->

                            <el-table-column label="操作" width="120">
                                <template slot-scope="scope">
                                    <RiskIconButton
                                        type="primary"
                                        icon="el-icon-edit"
                                        topTitle="编辑"
                                        @on-click="openEditFundDialog(scope.row)"
                                    ></RiskIconButton>
                                    <RiskIconButton
                                        type="danger"
                                        icon="el-icon-delete"
                                        topTitle="删除"
                                        @on-click="handleRemoveFund(scope.row.fundCode)"
                                    ></RiskIconButton>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="block">
                            <risk-pagination :paging="fundPage" @page-change="pageRetDetail"></risk-pagination>
                        </div>
                    </slot>
                </RiskRightModule>
                <!-- 新增\编辑敞口产品信息 -->
                <yh-dialog drag :title="fundDialogVO.title" :visible.sync="fundDialogVO.visible" width="400px" v-loading="loading">
                    <el-form label-width="100px" size="mini" ref="fundForm">
                        <el-form-item label="产品代码">
                            <el-select
                                style="width: 220px"
                                v-model="fundForm.fundCode"
                                placeholder="请选择"
                                :disabled="fundDialogVO.action === 2 ? true : false"
                            >
                                <el-option
                                    v-for="item in fundCodeSelectData"
                                    :key="item.fundCode"
                                    :label="item.fundCode + ' ' + item.fundNameSt"
                                    :value="item.fundCode"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="敞口值">
                            <el-input-number style="width: 220px" v-model="fundForm.exposureValue" controls-position="right"></el-input-number>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button size="mini" @click="closeFundDialog"> 取 消 </el-button>
                        <el-button size="mini" type="primary" @click="submitFundForm"> 确 定 </el-button>
                    </div>
                </yh-dialog>
                <!-- 删除敞口产品信息 -->
                <yh-dialog drag title="确认删除敞口下的敞口产品信息？" :visible.sync="removeFundDialog" width="500px" v-loading="loading">
                    <div class="remove-text">
                        <span v-for="(item, index) in fundCodeList" :key="index"> {{ item }} , </span>
                    </div>
                    <div slot="footer" class="dialog-footer">
                        <el-button size="mini" @click="removeFundDialog = false"> 取 消 </el-button>
                        <el-button size="mini" type="primary" @click="removeExposureFund">确 定 </el-button>
                    </div>
                </yh-dialog>

                <!-- 导入明细 -->
                <yh-dialog drag id="importDialog" title="导入敞口" :visible.sync="importFundDialog" width="650px" v-loading="loading">
                    <div style="height: 300px">
                        <el-button @click="handleUpload" type="primary">选择文件</el-button><i> {{ fileNames }} </i>
                        <input type="file" ref="fileInput" style="display: none" @change="selectfiles" />
                        <el-table :data="uploadTableData" style="width: 100%" border size="mini" max-height="300px">
                            <el-table-column label="敞口编号" prop="exposureId"></el-table-column>
                            <el-table-column label="产品编号" prop="fundCode" show-overflow-tooltip></el-table-column>
                            <el-table-column label="敞口值" prop="exposureValue" :formatter="setStatus"></el-table-column>
                        </el-table>
                    </div>
                    <span style="color: red">备注：导入格式请参考敞口导出的结果</span>
                    <div slot="footer" class="dialog-footer">
                        <el-button size="mini" @click="importFundDialog = false"> 取 消 </el-button>
                        <el-button size="mini" type="primary" @click="putDictDatas">确 定 </el-button>
                    </div>
                </yh-dialog>
            </template>
        </div>
    </div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { getCurrentPageData, formatterDate, formatterTime, formatter, formatterNumber, timeFormat, dateFormat } from '@/utils/tools';
import RiskLeftModule from '@/common/components/risk-left-module.vue';
import RiskRightModule from '@/common/components/risk-right-module.vue';
import RiskIconButton from '@/common/components/risk-icon-button.vue';
import RiskTrantable from '@/common/components/risk-trantable.vue';
import { DialogVO } from '@yhfin/biz';
import { SGU_CACHE } from '@/utils/diction-const-util';
import { downLoadFile } from '@/utils/request';
import * as XLSX from 'xlsx';
import XEUtils from 'xe-utils';
import RiskPagination from '@/common/components/risk-pagination.vue';

export interface pages {
    total?: number;
    pageSize?: number;
    currentPage?: number;
}

@Component({
    name: 'GradeIssue',
    components: {
        RiskLeftModule,
        RiskRightModule,
        RiskIconButton,
        RiskTrantable,
        RiskPagination,
    },
})
export default class GradeIssue extends Vue {
    formatterDate = formatterDate;
    formatterTime = formatterTime;
    formatter = formatter;
    formatterNumber = formatterNumber;
    dateFormat = dateFormat;
    timeFormat = timeFormat;

    private cutInfo: string = '外部';
    private treeData: any = [
        {
            label: '本地',
            id: 1,
            children: [],
        },
        {
            label: '外部',
            id: 2,
            children: [],
        },
    ];

    private exposurePage: pages = {
        total: 0,
        pageSize: 25,
        currentPage: 1,
    };
    private fundPage: pages = {
        total: 0,
        pageSize: 25,
        currentPage: 1,
    };

    private defaultExpandedKeys: any[] = [2];

    private leftplaceHolder: string = '编号/名称';
    private leftKey: string = '';
    private rightplaceHolder: string = '敞口编号/名称';
    private rightplaceHolder2: string = '产品代码/名称';

    private rightKey: string = '';
    private rightKey2: string = '';

    private leftHgt: string = '100vh';

    private exposureData: any[] = []; // 敞口信息表格数据
    private exposureDetialData: any[] = []; // 敞口明细表格数据

    private tableDisk: any[] = []; // 本地
    private tableSans: any[] = [];
    private tableDiskList: any[] = [];
    private tableSansList: any[] = [];

    private detailTableDisk: any[] = []; // 本地
    private detailTableSans: any[] = [];
    private detailTableDiskList: any[] = [];
    private detailTableSansList: any[] = [];

    private importFundDialog: boolean = false; // 导入敞口下的产品弹框
    private removeDialog: boolean = false; // 删除敞口信息弹框
    private removeFundDialog: boolean = false; // 删除敞口下的产品弹框

    private exposureDialogVO: DialogVO = new DialogVO(); // 敞口新增编辑弹框对象
    private fundDialogVO: DialogVO = new DialogVO(); // 产品新增、编辑弹框对象

    private exposureId: string = ''; // 选中的节点
    private exposureForm = {
        exposureId: '',
        exposureName: '',
        createType: '0',
    };
    private fundForm = {
        createType: '0',
        exposureId: '',
        exposureName: '',
        fundCode: '',
        exposureValue: undefined,
    };
    private editExposureForm: any = {};
    private editFundForm: any = {};
    private exposureIdList: any[] = [];
    private fundCodeList: any[] = [];
    private fundCodeSelectData: any[] = [];

    private uploadTableData: any[] = []; // 上传的数据
    private fileNames: string = ''; // 上传文件名
    private loading: boolean = false;

    async mounted() {
        // 获取产品信息 (产品序号下拉框数据)
        this.fundCodeSelectData = await SGU_CACHE('FundInfo', '/fundInfo/list', []);
        this.queryExposureList();
    }

    // 左边查询
    private submitInput(): void {}

    // 左边栏选择节点
    private clickNode(data: any): void {
        this.cutInfo = data.label;
        this.exposureId = data.id;
        this.fundForm.exposureId = this.exposureId;
        // 重置节点数据
        this.queryFundList(this.exposureId);
        if (this.cutInfo == '本地') {
            this.exposurePage.total = this.tableDisk.length;
            this.exposureData = this.tableDisk;
        } else if (this.cutInfo == '外部') {
            this.exposureData = this.tableSans;
            this.exposurePage.total = this.tableSans.length;
        } else {
            this.exposureForm.createType = data.data.createType === '0' ? '0' : '1';
            this.fundForm.createType = this.exposureForm.createType;
        }
    }

    //  树节点查询
    // private handleTreeSearch() {}

    /* ************************ 敞口相关 ***************************** */

    //  获取敞口信息
    private queryExposureList() {
        this.$axios.get('fundExposureSetting/fundExposure/queryAll').then((res: any) => {
            var local = [];
            var outside = [];
            let disk = [];
            let Sans = [];

            for (let item of res) {
                if (item.createType === '0') {
                    disk.push(item);
                    let datas = item.exposureId + '-' + item.exposureName;
                    local.push({ data: item, label: datas, id: item.exposureId });
                } else {
                    Sans.push(item);
                    let datas = item.exposureId + '-' + item.exposureName;
                    outside.push({ data: item, label: datas, id: item.exposureId });
                }
            }
            this.treeData[0].children = local;
            this.treeData[1].children = outside;
            this.tableDisk = disk;
            this.tableSans = Sans;
            this.tableDiskList = disk;
            this.tableSansList = Sans;
            if (this.cutInfo == '本地') {
                this.exposurePage.total = this.tableDisk.length;
                this.exposureData = getCurrentPageData(this.tableDisk, this.exposurePage.currentPage, this.exposurePage.pageSize);
            }
        });
    }

    // 查询敞口
    private searchExposure(): void {
        if (this.cutInfo === '本地') {
            this.tableDisk = this.handleFilter(this.tableDiskList, this.rightKey);
            this.exposurePage.total = this.tableDisk.length;
            this.exposureData = getCurrentPageData(this.tableDisk, this.exposurePage.currentPage, this.exposurePage.pageSize);
        } else {
            this.tableSans = this.handleFilter(this.tableSansList, this.rightKey);
            this.exposurePage.total = this.tableSans.length;
            this.exposureData = getCurrentPageData(this.tableSans, this.exposurePage.currentPage, this.exposurePage.pageSize);
        }
    }

    // 敞口筛选数据
    private handleFilter(dataSource: any, param: any): any {
        if (!param || !dataSource) {
            return dataSource;
        } else {
            return dataSource.filter(
                (item: any) =>
                    (item.exposureId || '').toUpperCase().includes(param.toUpperCase()) ||
                    (item.exposureName || '').toUpperCase().includes(param.toUpperCase())
            );
        }
    }

    // 敞口分页
    private pageRet(): void {
        this.exposurePage.total = this.tableDisk.length;
        this.exposureData = getCurrentPageData(this.tableDisk, this.exposurePage.currentPage, this.exposurePage.pageSize);
    }

    // 显示新增敞口弹框
    private openAddExposoreDialog() {
        this.exposureDialogVO = this.exposureDialogVO.getAddDialog('新增敞口信息');
    }

    // 显示编辑敞口弹框
    private openEditExposureDialog(row: any) {
        this.exposureForm.exposureId = row.exposureId;
        this.exposureForm.exposureName = row.exposureName;
        this.editExposureForm = row;
        this.exposureDialogVO = this.exposureDialogVO.getUpdateDialog('编辑敞口信息');
    }

    // 显示删除敞口弹框
    private openRemoveExposureDialog(val: any) {
        this.exposureIdList = [];
        this.handleExposureRemove(val);
    }

    // 关闭新增/编辑敞口弹框
    private closeExposureDialog() {
        this.exposureDialogVO.visible = false;
        this.exposureForm.exposureId = '';
        this.exposureForm.exposureName = '';
    }

    // 提交敞口信息表单
    private submitExposureForm() {
        if (this.exposureDialogVO.action === 1) {
            this.insertExposure();
        } else {
            this.editExposure();
        }
    }

    // 新增敞口
    private insertExposure() {
        if (!this.exposureForm.exposureName) {
            this.yh_message_warn('新增敞口名称不可为空');
            return;
        }
        if (this.exposureForm.exposureName.length > 50) {
            this.yh_message_warn('敞口名称太长');
            return;
        }

        this.$axios.post('fundExposureSetting/fundExposure/insert', this.exposureForm).then((res: any) => {
            this.closeExposureDialog();
            this.yh_message_success('新增成功');
            this.queryExposureList();
        });
    }

    // 编辑敞口
    private editExposure() {
        this.editExposureForm.exposureName = this.exposureForm.exposureName;
        if (!this.editExposureForm.exposureName) {
            this.yh_message_warn('修改敞口名称不可为空');
            return;
        }
        if (this.editExposureForm.exposureName.length > 50) {
            this.yh_message_warn('敞口名称太长');
            return;
        }
        this.$axios.post('fundExposureSetting/fundExposure/update', this.editExposureForm).then((res: any) => {
            this.closeExposureDialog();
            this.yh_message_success('更新成功');
            this.queryExposureList();
        });
    }

    // 选择敞口
    private handleSelectionChange(val: any): void {
        this.exposureIdList = [];
        for (var i in val) {
            this.exposureIdList.push(val[i].exposureId);
        }
    }

    // 判断敞口删除类型
    private handleExposureRemove(val: any) {
        if (val === -1) {
            if (!this.exposureIdList || this.exposureIdList.length < 1) {
                this.yh_message_warn('未选择删除项');
                return;
            }
        } else {
            this.exposureIdList = [];
            this.exposureIdList.push(val);
        }
        this.removeDialog = true;
    }

    // 删除敞口
    private removeExposure() {
        this.$axios({
            url: '/fundExposureSetting/fundExposure/delete',
            method: 'DELETE',
            data: this.exposureIdList,
        }).then(res => {
            this.yh_message_success('删除成功');
            this.queryExposureList();
            this.removeDialog = false;
        });
    }

    // 导出敞口信息
    private handleExport(val: string): void {
        let data = this.exposureIdList;
        if (!this.exposureIdList || this.exposureIdList.length < 1) {
            let values = this.cutInfo == '本地' ? this.tableDiskList : this.tableSansList;
            data = XEUtils.map(values, item => item.exposureId);
        }

        if (!data || data.length < 1) {
            this.yh_message_warn('导出列表为空,请添加数据在进行导出!');
            return;
        }

        downLoadFile({
            url: '/fundExposureSetting/fundExposure/outImport/' + this.exposureForm.createType,
            method: 'post',
            data: data,
        });
    }

    // 上传
    private handleUpload() {
        (this.$refs['fileInput'] as any).click();
    }

    // 选取文件
    private selectfiles(e) {
        let files = e.currentTarget.files;
        new Promise((resolve, reject) => {
            let reader = new FileReader();
            if (!files || files.length === 0) {
                // eslint-disable-next-line prefer-promise-reject-errors
                reject();
            }

            reader.readAsBinaryString(files[0]);
            reader.onload = e => {
                let webBook = XLSX.read(e.target.result, { type: 'binary' });
                let data = [];
                for (let sheet in webBook.Sheets) {
                    if (webBook.Sheets.hasOwnProperty(sheet)) {
                        data = data.concat(XLSX.utils.sheet_to_json(webBook.Sheets[sheet]));
                        break;
                    }
                }
                resolve(data);
            };
            reader.onerror = error => reject(error);
        }).then((res: any) => {
            let entryDetails;
            try {
                entryDetails = res
                    .map(item => {
                        return { exposureId: item.产品敞口编号, fundCode: item.产品代码, exposureValue: item.敞口值, key: item.产品敞口编号 };
                    })
                    .filter(item => !!item.fundCode);
                this.uploadTableData = entryDetails;
                this.fileNames = files[0].name;
                if (entryDetails.length === 0) {
                    this.yh_message_error('数据格式不正确或者数据为空，导入失败');
                    return;
                }
            } catch (e) {
                this.yh_message_error('数据格式不正确，导入失败');
                return;
            }
        });
    }

    // 导入
    private putDictDatas(): void {
        if (this.uploadTableData.length < 1) {
            this.yh_message_error('请上传需要导入的文件');
            return;
        }
        this.loading = true;
        this.$axios
            .post('/fundExposureSetting/fundExposure/insertByCode/' + this.exposureId, this.uploadTableData)
            .then(res => {
                this.yh_message_success('导入成功！');
                this.uploadTableData = [];
                this.fileNames = '';
                this.loading = false;
                this.queryFundList(this.exposureId);
                this.importFundDialog = false;
            })
            .catch(() => {
                this.yh_message_success('导入失败！');
                this.loading = false;
            });
    }

    /* ********************** 敞口产品相关 **************************** */

    // 获取敞口下的产品信息
    private queryFundList(exposureId: string) {
        this.$axios.get('fundExposureSetting/fundExposure/queryFundList/' + exposureId).then((res: any) => {
            this.detailTableDisk = res;
            this.detailTableDiskList = res;
            this.fundPage.currentPage = 1;
            this.pageRetDetail();
        });
    }

    // 敞口产品分页
    private pageRetDetail(): void {
        this.fundPage.total = this.detailTableDisk.length;
        this.exposureDetialData = getCurrentPageData(this.detailTableDisk, this.fundPage.currentPage, this.fundPage.pageSize);
    }

    // 查询敞口产品
    private searchExposureFund(): void {
        this.detailTableDisk = this.handleFilterFund(this.detailTableDiskList, this.rightKey2);
        this.fundPage.total = this.detailTableDisk.length;
        this.exposureDetialData = getCurrentPageData(this.detailTableDisk, this.fundPage.currentPage, this.fundPage.pageSize);
    }

    // 敞口产品筛选数据
    private handleFilterFund(dataSource: any, param: any): any {
        if (!param || !dataSource) {
            return dataSource;
        } else {
            return dataSource.filter(
                (item: any) =>
                    (item.fundCode || '').toUpperCase().includes(param.toUpperCase()) ||
                    (item.fundNameSt || '').toUpperCase().includes(param.toUpperCase())
            );
        }
    }

    // 显示新增产品敞口信息弹框
    private openAddFundDialog() {
        this.fundDialogVO = this.fundDialogVO.getAddDialog('新增敞口产品信息');
    }

    // 显示编辑产品敞口信息弹框
    private openEditFundDialog(row: any) {
        this.fundForm.fundCode = row.fundCode;
        this.fundForm.exposureValue = row.exposureValue;
        this.editFundForm = JSON.parse(JSON.stringify(row));
        this.fundDialogVO = this.fundDialogVO.getUpdateDialog('编辑敞口产品信息');
    }

    // 关闭新增/编辑产品敞口信息弹框
    private closeFundDialog() {
        this.fundDialogVO.visible = false;
        this.fundForm.fundCode = '';
        this.fundForm.exposureValue = undefined;
    }

    // 新增敞口下产品敞口信息
    private insertExposureFund() {
        let fundInfoCache = this.exposureDetialData;
        let existenceFundCode = fundInfoCache.map(item => item.fundCode);
        if (existenceFundCode.indexOf(this.fundForm.fundCode) > -1) {
            this.yh_message_warn('关联产品已存在,请重新选择!');
            return;
        }
        this.$axios.post('fundExposureSetting/fundExposure/insertByCode/' + this.exposureId, [this.fundForm]).then((res: any) => {
            this.queryFundList(this.exposureId);
            this.closeFundDialog();
            this.yh_message_success('新增成功');
        });
    }

    // 编辑敞口下产品敞口信息
    private updateExposureFund() {
        this.$axios.post('fundExposureSetting/fundExposure/updateByCode', this.editFundForm).then((res: any) => {
            this.queryFundList(this.exposureId);
            this.closeFundDialog();
            this.yh_message_success('更新成功');
        });
    }

    // 提交敞口产品信息表单
    private submitFundForm() {
        if (!this.fundForm.fundCode) {
            this.yh_message_warn('关联产品不可为空!');
            return;
        }
        if (!this.fundForm.exposureValue) {
            this.yh_message_warn('敞口值不可为空并且只能为数字!');
            return;
        }
        // let valueLength =;
        if (this.fundForm.exposureValue.length > 9) {
            this.yh_message_warn('敞口值长度不可超过9位!');
            return;
        }
        if (this.fundDialogVO.action === 1) {
            this.insertExposureFund();
        } else {
            this.editFundForm.exposureValue = this.fundForm.exposureValue;
            this.updateExposureFund();
        }
    }

    // 选择敞口产品信息
    private handleSelectionFundChange(val: any): void {
        this.fundCodeList = [];
        for (var i in val) {
            this.fundCodeList.push(val[i].fundCode);
        }
    }

    // 判断敞口产品信息删除类型
    private handleRemoveFund(val: any) {
        if (val === -1) {
            if (!this.fundCodeList || this.fundCodeList.length < 1) {
                this.yh_message_warn('未选择删除项');
                return;
            }
        } else {
            this.fundCodeList = [];
            this.fundCodeList.push(val);
        }
        this.removeFundDialog = true;
    }

    // 删除敞口下敞口产品信息
    private removeExposureFund() {
        this.$axios({
            url: '/fundExposureSetting/fundExposure/deleteByCode/' + this.exposureId,
            method: 'DELETE',
            data: this.fundCodeList,
        }).then(res => {
            this.yh_message_success('删除成功');
            this.queryFundList(this.exposureId);
            this.removeFundDialog = false;
            this.fundCodeList = [];
        });
    }

    // 导出敞口产品信息
    private handleExportFund(val: string): void {
        downLoadFile({
            url: '/fundExposureSetting/fundExposure/outByFundImport/' + this.exposureId,
            method: 'post',
            data: this.fundCodeList,
        });
    }
}
</script>
<style lang="scss" scoped>
.exposure-content {
    height: 100%;
}
.dict-r-slot {
    margin-left: 10px;
}
.importDialog {
    /deep/.el-dialog__body {
        max-height: 60vh;
    }
}
/deep/ .el-table--border th:first-child .cell {
    padding-left: 6px;
}
</style>
